home *** CD-ROM | disk | FTP | other *** search
/ Aminet 40 / Aminet 40 (2000)(Schatztruhe)[!][Dec 2000].iso / Aminet / dev / gui / MR_Classes.lha / MR_Classes / Dev / Source / tcpalette / Input.c < prev    next >
Encoding:
C/C++ Source or Header  |  2000-09-02  |  9.8 KB  |  328 lines

  1. #define DEBUG
  2. #include <debug.h>
  3.  
  4. #include "private.h"
  5. #include "protos.h"
  6.  
  7. ULONG pr_Mix(ULONG A,ULONG B, float Percent);
  8.  
  9. #define MRK_BUFFER_SIZE 3
  10.  
  11. ULONG __saveds gad_HandleInput(Class *C, struct Gadget *Gad, struct gpInput *Input)
  12. {
  13.   ULONG retval;
  14.   char buffer[MRK_BUFFER_SIZE];
  15. //  LONG  key;
  16.   struct GadData *gdata;
  17.   struct InputEvent *ie; 
  18.   
  19.   gdata=INST_DATA(C, Gad);
  20.   retval = GMR_MEACTIVE;
  21.   ie = Input->gpi_IEvent;
  22.  
  23.   if(gdata->Disabled) 
  24.     return(GMR_NOREUSE);
  25.  
  26.   switch(ie->ie_Class)
  27.   {
  28.     case IECLASS_RAWKEY:
  29. //      KP("RAW KEY CODE - %lx %8lx\n",ie->ie_Code,ie->ie_Qualifier);
  30. //        gdata->gd_MouseMode=0;
  31.       
  32.       switch(ie->ie_Code)
  33.       {
  34.         case 0x4c: // UP
  35.           {
  36.             LONG t;
  37.             
  38.             t=gdata->ActivePen-gdata->Cols;
  39.             if(t<0) t+=gdata->Pens;
  40.             if(t<0) t=0; // double check!
  41.             gdata->ActivePen=t;
  42.             
  43.             gad_Render(C,Gad,(APTR)Input,GREDRAW_UPDATE);      
  44.             i_Notify(C,Gad,(APTR)Input, 0);
  45.           }
  46.           break;
  47.         
  48.         case 0x4f: // LEFT
  49.           {
  50.             LONG t;
  51.             
  52.             t=gdata->ActivePen-1;
  53.             if(t<0) t=gdata->Pens-1;
  54.             gdata->ActivePen=t;
  55.             
  56.             gad_Render(C,Gad,(APTR)Input,GREDRAW_UPDATE);      
  57.             i_Notify(C,Gad,(APTR)Input, 0);
  58.           }            
  59.           break;
  60.           
  61.         case 0x4e: // RIGHT
  62.           {
  63.             LONG t;
  64.             
  65.             t=gdata->ActivePen+1;
  66.             if(t>=gdata->Pens) t=0;
  67.             gdata->ActivePen=t;
  68.             
  69.             gad_Render(C,Gad,(APTR)Input,GREDRAW_UPDATE);      
  70.             i_Notify(C,Gad,(APTR)Input, 0);
  71.           }
  72.           break;            
  73.         
  74.         case 0x4d: // DOWN
  75.           {
  76.             LONG t;
  77.             
  78.             t=gdata->ActivePen+gdata->Cols;
  79.             if(t>=gdata->Pens) t-=gdata->Pens;
  80.             if(t>=gdata->Pens) t=0; // double check!
  81.             gdata->ActivePen=t;
  82.             
  83.             gad_Render(C,Gad,(APTR)Input,GREDRAW_UPDATE);      
  84.             i_Notify(C,Gad,(APTR)Input, 0);
  85.           }
  86.           break;
  87.           
  88.         default:
  89.           if(MapRawKey(ie,buffer,MRK_BUFFER_SIZE,0))
  90.           {
  91.        //     KP("%ld %lc\n",buffer[0],buffer[0]);
  92.             
  93.             switch(buffer[0])
  94.             {
  95.               case 27: // Esc
  96.                 retval=GMR_NOREUSE;
  97.                 break;
  98.               case 155: //  Shift + TAB
  99.                 retval=GMR_NOREUSE | GMR_PREVACTIVE;
  100.                 break;
  101.               case  9:  // TAB
  102.                 retval=GMR_NOREUSE | GMR_NEXTACTIVE;
  103.                 break;
  104.               case 0x20:
  105. //                  step=(shifted?-1:1);
  106.                 break;
  107.             }
  108.           }
  109.           break;
  110.       }
  111.       break;
  112.     case IECLASS_RAWMOUSE:
  113.       {
  114.         LONG x,y;
  115.         LONG r,c;
  116.         
  117. //        retval = GMR_MEACTIVE;
  118.         
  119.         x=(Input->gpi_Mouse).X+Gad->LeftEdge;
  120.         y=(Input->gpi_Mouse).Y+Gad->TopEdge;
  121.         
  122. //          DKP("RawMouse %ld %ld\n", x, y);
  123.         if(gdata->MouseMode)
  124.         {
  125.           for(r=0; r<gdata->Rows; r++)
  126.           {
  127.             if(y>=gdata->Row[r] && y<gdata->Row[r+1])
  128.               break;
  129.           }
  130.           
  131.           for(c=0; c<gdata->Cols; c++)
  132.           {
  133.             if(x>=gdata->Col[c] && x<gdata->Col[c+1])
  134.               break;
  135.           }
  136.           
  137. //          DKP("  c=%ld r=%ld\n", c, r);
  138.           
  139.           if(c<gdata->Cols && r<gdata->Rows)
  140.           {
  141.             gdata->ActivePen=r * gdata->Cols + c;
  142.             if(gdata->ActivePen!=gdata->LastActivePen)
  143.             {
  144.               i_StoreUndoIfNeeded(C,Gad,Input);
  145.               i_Notify(C,Gad,(APTR)Input, OPUF_INTERIM);
  146.               gad_Render(C,Gad,(APTR)Input,GREDRAW_UPDATE);
  147.             }
  148.           }
  149.         }
  150.  
  151.         switch(ie->ie_Code)
  152.          {
  153.           case SELECTUP:
  154.              gdata->MouseMode=0;
  155.           
  156.  
  157.             {// inside gadget
  158.               ULONG em;
  159.               
  160.               em=gdata->EditMode;
  161.               gdata->EditMode=0;
  162.               
  163.               
  164.               switch(em)
  165.               {
  166.                 case TCPEM_COPY:
  167.                   i_AddUndo(gdata, gdata->ActivePen,0,0);
  168.                   gdata->Palette[gdata->ActivePen]=gdata->Palette[gdata->EMPen];
  169.                   gad_Render(C,Gad,(APTR)Input,GREDRAW_UPDATE);
  170.                   break;
  171.                 case TCPEM_SPREAD:
  172.                   {
  173.                     ULONG l,c1,c2,c3,r1,r2,g1,g2,b1,b2;
  174.                     float p;
  175.                       
  176.                       
  177. //                        pr_SetUndoBuffer(PReq);
  178.                     
  179.                     if(gdata->EMPen>gdata->ActivePen)
  180.                     {
  181.                       c1=gdata->ActivePen;
  182.                       c2=gdata->EMPen;
  183.                     }
  184.                     else
  185.                     {
  186.                       c2=gdata->ActivePen;
  187.                       c1=gdata->EMPen;
  188.                     }
  189.                     
  190.                     c3=c2-c1;
  191.                     
  192.                     if(c3>1)
  193.                     {
  194.                       r1=gdata->Palette[c1].R;
  195.                       g1=gdata->Palette[c1].G;
  196.                       b1=gdata->Palette[c1].B;
  197.                       
  198.                       r2=gdata->Palette[c2].R;
  199.                       g2=gdata->Palette[c2].G;
  200.                       b2=gdata->Palette[c2].B;
  201.  
  202.                       for(l=c1+1;l<c2;l++)
  203.                       {
  204.                         i_AddUndo(gdata, l ,0,!(l==(c1+1)));                
  205.                         p=(float)(l-c1)/(float)c3;
  206.                         gdata->Palette[l].R       =pr_Mix(r1,r2,p);
  207.                         gdata->Palette[l].G       =pr_Mix(g1,g2,p);
  208.                         gdata->Palette[l].B       =pr_Mix(b1,b2,p);  
  209.                       }
  210.                     }
  211.                   }
  212.                   gad_Render(C,Gad,(APTR)Input,GREDRAW_REDRAW);
  213.                   break;
  214.                 case TCPEM_SWAP:
  215.                   {
  216.                     struct TCPaletteRGB dummy;
  217.  
  218.                     i_AddUndo(gdata, gdata->ActivePen ,0,0);  
  219.                     i_AddUndo(gdata, gdata->EMPen     ,0,1);  
  220.                                         
  221.                     dummy=gdata->Palette[gdata->ActivePen];
  222.                     gdata->Palette[gdata->ActivePen]=gdata->Palette[gdata->EMPen];
  223.                     gdata->Palette[gdata->EMPen]=dummy;
  224.                   }
  225.                   
  226.                   gad_Render(C,Gad,(APTR)Input,GREDRAW_REDRAW);
  227.                   break;
  228.                   
  229.                 default:
  230.                   gad_Render(C,Gad,(APTR)Input,GREDRAW_UPDATE);
  231.               }                
  232.               
  233.               i_Notify(C,Gad,(APTR)Input, 0);
  234.               
  235.               retval = GMR_MEACTIVE;
  236. //              retval = GMR_NOREUSE;
  237.             }
  238.             break;
  239.          
  240.           case SELECTDOWN:
  241.              if ( ((Input->gpi_Mouse).X < 0) ||
  242.                  ((Input->gpi_Mouse).X >= Gad->Width) ||
  243.                  ((Input->gpi_Mouse).Y < 0) ||
  244.                  ((Input->gpi_Mouse).Y >= Gad->Height) )
  245.             {// outside gadget
  246.               
  247.               if(gdata->EditMode)
  248.               {
  249.                 gdata->EditMode=0;
  250.                 gad_Render(C,Gad,(APTR)Input,GREDRAW_UPDATE);
  251.                 i_Notify(C,Gad,(APTR)Input, 0);
  252.               }
  253. //              retval = GMR_NOREUSE | GMR_VERIFY;
  254.               retval = GMR_REUSE;
  255.             }
  256.             else
  257.             {
  258.               gdata->MouseMode=1;
  259.               gad_Render(C,Gad,(APTR)Input,GREDRAW_UPDATE);
  260.               i_Notify(C,Gad,(APTR)Input, 0);
  261.               retval = GMR_MEACTIVE;
  262.             }
  263.             break;
  264.             
  265.           case MENUDOWN: /* The user hit the menu button. Go inactive and let      */
  266.                                      /* Intuition reuse the menu button event so Intuition can */
  267.                                      /* pop up the menu bar.                                   */
  268.             if(gdata->EditMode)//                                                                      (44.3.1) (09/01/00)
  269.             {//                                                                                        (44.3.1) (09/01/00)
  270.               gdata->EditMode=0;//                                                                     (44.3.1) (09/01/00)
  271.               gad_Render(C,Gad,(APTR)Input,GREDRAW_UPDATE);//                                          (44.3.1) (09/01/00)
  272.               i_Notify(C,Gad,(APTR)Input, 0);//                                                        (44.3.1) (09/01/00)
  273.             }//                                                                                        (44.3.1) (09/01/00)
  274.             retval = GMR_REUSE;
  275.                                           /* Since the gadget is going inactive, send a final   */
  276.                                          /* notification to the ICA_TARGET.                    */
  277. //          NotifyPulse(Class , o, 0L, inst->midX, (struct gp_Input *)msg);
  278.             break;
  279.           default:
  280.             retval = GMR_MEACTIVE;
  281.         }
  282.       }
  283.       break;
  284.   }
  285.   
  286.   if(retval!=GMR_MEACTIVE)
  287.   {
  288.     i_Notify(C,Gad,(APTR)Input, 0);
  289.   }
  290.   
  291.   return(retval);
  292. }
  293.  
  294.  
  295. ULONG pr_Mix(ULONG A,ULONG B, float Percent)
  296. {
  297.   float a,b,diff;
  298.   
  299.   a=A;
  300.   b=B;
  301.   
  302.   diff=b-a;
  303.  
  304.   a+=diff*Percent;
  305.  
  306.   return((ULONG) (a));
  307. }
  308.  
  309.  
  310.  
  311. /*
  312.  
  313.              if ( ((Input->gpi_Mouse).X < 0) ||
  314.                  ((Input->gpi_Mouse).X >= Gad->Width) ||
  315.                  ((Input->gpi_Mouse).Y < 0) ||
  316.                  ((Input->gpi_Mouse).Y >= Gad->Height) )
  317.             {// outside gadget
  318.               
  319.               if(gdata->EditMode)
  320.               {
  321.                 gdata->EditMode=0;
  322.                 gad_Render(C,Gad,(APTR)Input,GREDRAW_UPDATE);
  323.               }
  324. //              retval = GMR_NOREUSE | GMR_VERIFY;
  325.               retval = GMR_MEACTIVE;
  326.             }
  327.             else
  328. */